package com.heima.admin.controller;
// 爱情不是随便许诺,算了,不想再说了

import com.heima.admin.entity.AdSensitive;
import com.heima.admin.service.AdSensitiveService;
import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.exception.LeadException;
import com.heima.model.admin.dtos.SensitiveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 敏感词crud
 */
@RestController
public class SensitiveController {



    @Autowired
    private AdSensitiveService sensitiveService;

    /**
     * 敏感词列表查询
      * @param dto
     * @return
     */
    @PostMapping("/api/v1/sensitive/list")
    public PageResult<AdSensitive> findByPage(@RequestBody SensitiveDto dto){
        PageResult<AdSensitive> byPage = sensitiveService.findByPage(dto);
        return byPage;
    }


    /**
     * 添加敏感词
     * @param adSensitive
     * @return
     */
    @PostMapping("/api/v1/sensitive/save")
    public ResponseResult save(@RequestBody AdSensitive adSensitive){
        sensitiveService.saveSensitive(adSensitive);
        return ResponseResult.ok();
    }


    /**
     * 修改敏感词
     * @param dto
     * @return
     */
    @PutMapping("/api/v1/sensitive/update")
    public ResponseResult updateById(@RequestBody SensitiveDto dto){
        sensitiveService.updateByIdSensitive(dto);
        return ResponseResult.ok();
    }


    /**
     * 删除敏感词
     * @param dto
     * @return
     */
    @DeleteMapping("/api/v1/sensitive/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id){
        sensitiveService.deleteById(id);
        return ResponseResult.ok();
    }
}
